const { notEmpty, bigCamelCase } = require('../utils.js')

module.exports = {
  description: '生成一个页面文件(默认生成在src/views文件夹中)',
  prompts: [
    {
      type: 'input',
      name: 'path',
      message: '请输入路径(根路径是src/views, eg: /system/user)：',
      validate: notEmpty('path')
    },
    {
      type: 'input',
      name: 'menuTitle',
      message: '请输入菜单标题：',
      validate: notEmpty('menuTitle')
    },
    {
      type: 'input',
      name: 'menuIcon',
      message: '请输入菜单icon：',
      validate: notEmpty('menuIcon')
    }
  ],
  actions: (data) => {
    const { path, menuTitle, menuIcon } = data
    const _path = path.charAt(0) !== '/' ? '/' + path : path
    const pathItemList = _path.split('/')
    const name = pathItemList.slice(-1)[0]
    const compPath = '/' + pathItemList.slice(1, -1).join('/')
    console.log(compPath)
    const bigName = bigCamelCase(name)

    const actions = [
      {
        type: 'add',
        path: `src/views${compPath}/${name}/index.vue`,
        templateFile: 'plop-templates/view/index.hbs',
        data: {
          name,
          bigName,
          compPath,
          menuTitle,
          menuIcon
        }
      }
    ]

    return actions
  }
}
